<#import "/admin/_layout.html" as layout>
<@layout.header "模板管理"></@layout.header>
<@layout.body>
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-left">
                        <li class="breadcrumb-item"><a href="#">模板</a></li>
                        <li class="breadcrumb-item active">列表</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <section class="content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-body">
                    <div class="row">
                        <a href="/admin/template/install" class="btn btn-info"><i class="fas fa-plus"></i> 安装</a>
                    </div>
                    <table class="table table-hover" style="width:100%">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>模板名称</th>
                            <th>模板路径</th>
                            <th>模板版本</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <#list templates as item>
                            <tr>
                                <td>${item.id!}</td>
                                <td>${item.name!}</td>
                                <td>${item.path!}</td>
                                <td>${item.version!}</td>
                                <td>
                                    <a class="unInstall_a" href="javascript:void(0)" id="${item.id!}">卸载</a>
                                    <#if item.id != (enableTemplate.id)!>
                                        <a class="active_a" href="javascript:void(0)" id="${item.id!}">启用</a>
                                    <#else>
                                        <span style="color: #00b44e">正在使用</span>
                                    </#if>
                                </td>
                            </tr>
                        </#list>
                    </table>
                </div>
            </div>
        </div>
    </section>
</@layout.body>
<@layout.script>
    <script type="text/javascript">
        $(document).ready(function() {
            $(".active_a").click(function() {
                var templateId = $(this).attr("id");
                layer.confirm('确定要启用模板吗?', {
                    btn : ['确定', '取消']
                }, function(i) {
                    layer.close(i);
                    ajaxPost("/admin/template/doEnable", {templateId: templateId}, function () {
                        alertSuccess("启用成功", function(){
                            location.href = "/admin/template/list";
                        })
                    })
                });
            })

            $(".unInstall_a").click(function() {
                var templateId = $(this).attr("id");
                layer.confirm('确定要卸载模板吗?', {
                    btn : ['确定', '取消']
                }, function(i) {
                    layer.close(i);
                    ajaxPost("/admin/template/doUnInstall", {templateId: templateId}, function () {
                        alertSuccess("卸载成功", function(){
                            location.href = "/admin/template/list";
                        })
                    })
                });
            })
        });
    </script>
</@layout.script>